package org.scau.studentevaluation.utils;

import lombok.extern.slf4j.Slf4j;

import java.util.concurrent.Callable;

/**
 * @ClassName: TimeIt
 * @Description: TODO
 * @Author: sunslikes
 * @Date: 2020/9/3 2:27
 * @Version: 1.0
 */
@Slf4j
public class TimeUtils {
    public static <T> T printTime(Callable<T> task) {
        T call = null;
        try {
            long startTime = System.currentTimeMillis();
            call = task.call();
            log.info(task.getClass().getSimpleName() + " cost: " + (System.currentTimeMillis() - startTime) / 1000d + "s");
        } catch (Exception e) {
            e.printStackTrace();
        }
        return call;
    }
    public static void printTime(Runnable task) {
        try {
            long startTime = System.currentTimeMillis();
            task.run();
            log.info(task.getClass().getSimpleName() + " cost: " + (System.currentTimeMillis() - startTime) / 1000d + "s");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
